import publicForm from "@/components/public/up-form.vue"; //弹框form
import publicForm1 from "@/components/public/el-form.vue"; //弹框form

import formJs from "./regexDetail.js"; //新增弹框配置项
import {
    getBaseDepartmentUser, //提交审核人
    saveWorkplanInformation, //计划保存
    getWorkplanInformationByFid, //详情
    CheckWorkplanInformation, // 计划审核
    saveWorkplanFinishInformation, //完成保存
    CheckWorkplanFinishInformation, //完成审核
} from "@/api/request.js";
export default {
    props: [
        "dialogVisible",
        "dialogTitle",
        "projectId",
        "status",
        "statusNum",
        "dataFid",
        "currentRow",
        "projectName",
        "stationType",
    ],
    data() {
        return {
            visible: "",
            title: "新增",
            isLock: false, // 控制按钮的disable属性
            btnStatus: [],
            dialogHeight: null,
            activeIndex: "1",
            formObj: formJs.formObj,
            projectNames: null,
            currntData: null,
            dataInfo: null,
            formData: {
                fId: "", //传此表示修改
                userId: "", //当前登录人id
                userName: "", //当前登录人名称
                fProjectname: "", //当前登录人项目名称(如果是项目部的保存接口,传这个人的所在上级的项目id)
                fProjectid: "", //当前登录人项目ID
                fCompanyname: "", //当前登录人标段名称
                fCompanyid: "", //当前登录人标段ID
                fPreparacompanyname: "", //计划编制单位名称
                fPreparacompanyid: "", //计划编制单位id
                fPlantype: "", //计划类型
                fPlannumber: "", //计划编号
                fPlanname: "", //计划名称
                fAffiliationyear: this.common.getYear(0), //隶属年度
                fAffiliationmonth: this.common.getMonth(0), //隶属月度
                fPlandescription: "", //关键计划简述
                fReportid: "", //填报人id
                fReportname: "", //填报人姓名
                fReportdates: this.common.getDay(0), //填报日期
                fWorkfile: "", //工作计划资料
                fSubcheckid: "", //提交审核人id
                fSubcheckname: "", //提交审核人姓名
                fSubcheckunitid: "", //提交审核人的单位id projectId
                fCcpeople: "", //传阅人姓名
                fCcpeopleid: "", //传阅人id
                recordfiles: [],
                fType: null
            },
            fWorkfilelist: [], //工作计划资料
            fCcpeopleData: [], //计划传阅人
            fFinishccpeopleData: [], //完成传阅人
            planReview: formJs.planReview, //计划审核
            planReviewData: {
                fId: "", //修改与保存都必须传
                fCheckstatus: "", //审核结果(内容详实,审核通过。)(内容不实，重新上报。)  如审核未通过 打回上一级 状态为”已打回“ 已打回状态下只能删除不能修改
                fCheckdescription: "", //审核说明
                fCheckid: "", //审核人id
                fCheckname: "", //审核人姓名
                fCheckunitid: "", ///审核人所在的单位id
                fCheckunitname: "", ///审核人所在的单位名称
                fCheckdates: this.common.getDay(0), //审核时间
                userId: "", //当前登录人id
                userName: "", //当前登录人姓名
            }, //计划审核
            btnShow: true,
            formFinishObj: formJs.formFinishObj, // 完成情况信息
            formFinishData: {
                fId: "", //修改与保存都必须传
                fDatanumber: "", //资料编号
                fDataname: "", //资料名称
                fKeydescription: "", //关键内容简述
                fFinishreportid: "", //完成情况填报人id
                fFinishreportname: "", //完成情况填报人姓名
                fFinishreportdates: this.common.getDay(0), //完成情况填报日期
                fFinishfileurl: "", //工作完成资料
                fFinshsubcheckid: "", //完成情况提交审核人id
                fFinshsubcheckname: "", //完成情况提交审核人姓名
                fFinshsubcheckunitid: "", //完成情况提交审核人所在的单位id
                fFinishccpeople: "", //完成情况传阅人姓名
                fFinishccpeopleid: "", //完成情况传阅人id
                userId: "", //当前登录人id
                userName: "", //当前登录人姓名
                recordfiles: [],

            }, // 完成情况信息
            FinishfileList: [], //工作计划资料
            fFinishccpeople: [], //计划传阅人
            planFinishReview: formJs.planFinishReview, // 完成情况信息审核
            planFinishReviewData: {
                fId: "", //修改与保存都必须传
                fFinishcheckstatus: "", //完成情况审核结果(内容详实,审核通过。)(内容不实，重新上报。) 如未通过 打回上一级（完成情况修改） 可修改不可删除
                fFinishcheckdescription: "", //完成情况审核说明
                fFinshcheckid: "", //完成情况审核人id
                fFinshcheckname: "", //完成情况审核人姓名
                fFinshcheckunitid: "", //完成情况审核人单位id
                fFinshcheckunitname: "", //完成情况审核人单位名称
                fFinshcheckdates: this.common.getDay(0), //完成情况审核时间
                userId: "", //当前登录人id
                userName: "", //当前登录人姓名
            }, // 完成情况信息审核
            currentStatus: null,
            // 多选
            dialogTree: false,
            loadingtree: false,
            companyInfo: [], //单位
            departmentList: [], //部门
            checkboxGroup: [],
            personList: [],
            newData: [],
            boys: require("@/assets/img/organization/boys.png"),
            girls: require("@/assets/img/organization/girls.png"),
            allUserInfo: [],
            propTitle: null,
        };
    },
    components: {
        publicForm,
        publicForm1
    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
        dialogTitle: {
            handler(newVal) {
                if (newVal) {
                    this.title = newVal;
                }
            },
            immediate: true,
        },
        stationType: {
            handler(newVal) {
                if (newVal) {
                    this.stationtype = newVal;
                }
            },
            immediate: true,
        },
        projectId: {
            handler(newVal) {
                if (newVal) {
                    this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
                    if(this.userInfo.companyNature == '施工单位'){
                        this.getPerson(this.userInfo.projectId);
                    }else{
                        this.getPerson("99ca0578-fceb-4f58-b1b2-dbec0db96e6e");
                    }
                    // this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
                    // if (this.userInfo.companyNature == '分子公司') {
                    //     this.getPerson(newVal);
                    // } else if (this.userInfo.companyNature == '建设单位') {
                    //     this.getPerson("99ca0578-fceb-4f58-b1b2-dbec0db96e6e");
                    // }
                }
            },
            immediate: true,
        },
        projectName: {
            handler(newVal) {
                console.log(44, newVal);
                if (newVal) {
                    this.projectNames = newVal
                }
            },
            immediate: true,
        },
        status: {
            handler(newVal) {
                if (newVal) {
                    this.btnStatus = newVal;
                }
            },
            immediate: true,
        },
        statusNum: {
            handler(newVal) {
                if (newVal) {
                    this.edit(newVal);
                }
            },
            immediate: true,
        },
        dataFid: {
            handler(newVal) {
                if (newVal) {
                    this.currntData = newVal;
                    if (this.statusNum != 1) {
                        this.formData = this.$options.data.call(this).formData;
                        this.getDetail(newVal);
                    }
                }
            },
            immediate: true,
        },
        currentRow: {
            handler(newVal) {
                if (newVal) {
                    this.currentStatus = newVal;
                }
            },
            immediate: true,
        },
    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
        this.btnShow = true
        if (this.statusNum == 1) {
            this.formData = this.$options.data.call(this).formData;
            //新增
            this.formData.fReportid = this.userInfo.userId; //当前登录人id
            this.formData.fReportname = this.userInfo.realName; //当前登录人名称
            this.formData.fWorkfile = "BehaViorManage" + Date.now();
            this.formData.fPreparacompanyname = this.userInfo.companyName; //当前登录人标段名称
            this.formData.fPreparacompanyid = this.userInfo.companyId; //当前登录人标段ID
            // 新增
            this.formObj.map((item) => {
                item.disabled = false;
            });
            this.formObj[0].disabled = true;
            this.formObj[9].uploadSelect = true;
            // 计划审核
            this.planReview.map((item) => {
                item.disabled = true;
            });
            // 完成情况
            this.formFinishObj.map((item) => {
                item.disabled = true;
            });
            this.formObj[5].uploadSelect = false;
        } else if (this.statusNum == 2) { //完成情况
            this.formFinishData = this.$options.data.call(this).formFinishData;
            this.formObj.map((item) => {
                item.disabled = true;
            });
            this.formObj[9].uploadSelect = false;
            // 计划审核
            this.planReview.map((item) => {
                item.disabled = true;
            });
            // 完成情况
            this.formFinishObj.map((item) => {
                item.disabled = false;
            });
            this.formFinishObj[4].disabled = true;

            this.formFinishObj[5].uploadSelect = true;
        } else if (this.statusNum == 3) { //编辑
            //编辑
            this.formData = this.$options.data.call(this).formData;
            this.formObj.map((item) => {
                item.disabled = false;
            });
            this.formObj[0].disabled = true;
            this.formObj[9].uploadSelect = true;

            // 计划审核
            this.planReview.map((item) => {
                item.disabled = true;
            });
            // 完成情况
            this.formFinishObj.map((item) => {
                item.disabled = true;
            });
            this.formObj[5].uploadSelect = false;
        } else if (this.statusNum == 6) { //审核
            this.formObj.map((item) => {
                item.disabled = true;
            });
            this.formObj[9].uploadSelect = false;
            if (this.currentStatus.fStatuss == "待审核") {
                this.planReviewData = this.$options.data.call(this).planReviewData;
                //计划审核
                this.planReviewData.fCheckid = this.userInfo.userId; //审核人id
                this.planReviewData.fCheckname = this.userInfo.realName; //审核人姓名
                // 计划审核
                this.planReview.map((item) => {
                    item.disabled = false;
                });
                this.planReview[2].disabled = true;
                // 完成情况
                this.formFinishObj.map((item) => {
                    item.disabled = true;
                });
                this.planFinishReview.map((item) => { //完成审核
                    item.disabled = true;
                });
            } else if (this.currentStatus.fStatuss == "审核中") {
                this.planFinishReviewData = this.$options.data.call(this).planFinishReviewData;

                // 完成审核
                this.planFinishReviewData.fFinshcheckid = this.userInfo.userId; //完成情况审核人id
                this.planFinishReviewData.fFinshcheckname = this.userInfo.realName; //完成情况审核人姓名
                // 计划审核
                this.planReview.map((item) => {
                    item.disabled = true;
                });
                // 完成情况
                this.formFinishObj.map((item) => {
                    item.disabled = true;
                });
                this.formObj[5].uploadSelect = false;
                this.planFinishReview.map((item) => { //完成审核
                    item.disabled = false;
                });
            }
        } else if (this.statusNum == 7) { //查看
            this.btnShow = false
            this.formObj.map((item) => {
                item.disabled = true;
            });
            this.formObj[9].uploadSelect = false;
            // 计划审核
            this.planReview.map((item) => {
                item.disabled = true;
            });

            // 完成情况
            this.formFinishObj.map((item) => {
                item.disabled = true;
            });

            this.formFinishObj[5].uploadSelect = false;

            this.planFinishReview.map((item) => {
                item.disabled = true;
            });
        }

        this.getHeight();
    },
    methods: {
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.76 + "px";
        },
        handleSelect(key) {
            this.activeIndex = key;
        },
        closeDialog() {
            this.$emit("close");
        },
        // fCcpeopleData计划传阅人
        selectChange(data, a, b) {
            console.log(data, a, b, this.formData);
            if (b == "fSubcheckname") {
                this.formData.fSubcheckid = data.value;
                this.formData.fSubcheckname = data.label;
            } else if (b == "fFinshsubcheckname") {
                this.formFinishData.fFinshsubcheckid = data.value; //完成情况提交审核人id
                this.formFinishData.fFinshsubcheckname = data.label; //完成情况提交审核人姓名
            } else if (b == "fPlantype") {
                if (data == '月度计划') {
                    this.formData.fAffiliationmonth = this.common.getMonth(0)
                } else {
                    this.formData.fAffiliationmonth = "/"


                }
            }
        },
        edit(status) {
            if (status == 1) {
                this.formData = this.$options.data.call(this).formData;
            } else if (status == 3) {
                this.formData = this.$options.data.call(this).formData;
            }
        },
        // 详情
        getDetail(id) {
            getWorkplanInformationByFid({
                fId: id
            }).then((res) => {
                var data = res.data.yjQmpMsWorkplanInformation;
                this.dataInfo = data.fId
                if (this.currentStatus.fStatuss == "编辑中") {
                    this.formData = res.data.yjQmpMsWorkplanInformation;
                    this.formData.fAffiliationyear = data.fAffiliationyear.substr(0, 4);
                    this.checkboxGroup = []
                    this.allUserInfo = []
                    this.checkboxGroup = res.data.yjQmpMsWorkplanInformation.fCcpeopleid.split(",");
                    var fCcpeopleName = res.data.yjQmpMsWorkplanInformation.fCcpeople.split(",");
                    this.newData = []
                    fCcpeopleName.map((item, index) => {
                        this.newData.push({
                            fRealname: item,
                            fGender: "1",
                            fDepartmentName: "",
                            fAccount: "",
                            fUserid: this.checkboxGroup[index]
                        })
                    })
                    this.allUserInfo = this.newData
                    // 计划情况
                    this.formData.recordfiles = [];
                    this.fWorkfilelist = res.data.fWorkfilelist; //计划资料附件
                } else if (this.currentStatus.fStatuss == "待审核") {
                    this.formData = res.data.yjQmpMsWorkplanInformation;
                    this.formData.fAffiliationyear = data.fAffiliationyear.substr(0, 4);
                    this.fWorkfilelist = res.data.fWorkfilelist; //计划资料附件
                } else if (this.currentStatus.fStatuss == '执行中') {
                    this.formData = res.data.yjQmpMsWorkplanInformation;
                    this.formData.fAffiliationyear = data.fAffiliationyear.substr(0, 4);
                    this.fWorkfilelist = res.data.fWorkfilelist; //计划资料附件
                    //    计划审核
                    this.planReviewData = res.data.yjQmpMsWorkplanInformation; //"待审核"

                    if (data.fDatanumber != '' && data.fDatanumber != null) {
                        this.formFinishData = res.data.yjQmpMsWorkplanInformation; //"执行中"
                        this.FinishfileList = res.data.fFinishfileurllist
                        this.checkboxGroup = []
                        this.allUserInfo = []
                        if (res.data.yjQmpMsWorkplanInformation.fFinishccpeople != '') {
                            this.checkboxGroup = res.data.yjQmpMsWorkplanInformation.fFinishccpeopleid.split(",");
                            var fFinishccpeopleName = res.data.yjQmpMsWorkplanInformation.fFinishccpeople.split(",");
                            console.log(5656, res.data.yjQmpMsWorkplanInformation.fFinishccpeople, fFinishccpeopleName);
                            this.newData = []
                            fFinishccpeopleName.map((item, index) => {
                                this.newData.push({
                                    fRealname: item,
                                    fGender: "1",
                                    fDepartmentName: "",
                                    fAccount: "",
                                    fUserid: this.checkboxGroup[index]
                                })
                            })
                            this.allUserInfo = this.newData
                        }
                    } else {
                        this.formFinishData.fFinishfileurl = "BehaViorFinishManage" + Date.now();
                        this.formFinishData.fFinishreportid = this.userInfo.userId; //完成情况填报人id
                        this.formFinishData.fFinishreportname = this.userInfo.realName; //完成情况填报人姓名
                        this.formFinishData.userId = this.userInfo.userId; //当前登录人id
                        this.formFinishData.userName = this.userInfo.realName; //当前登录人名称
                        this.formFinishData.fId = this.dataInfo
                        this.formFinishData.fFinshsubcheckunitid = this.projectId
                    }
                } else if (this.currentStatus.fStatuss == '审核中') {
                    this.formData = res.data.yjQmpMsWorkplanInformation;
                    this.formData.fAffiliationyear = data.fAffiliationyear.substr(0, 4);
                    this.fWorkfilelist = res.data.fWorkfilelist; //计划资料附件
                    // 计划审核
                    this.planReviewData = res.data.yjQmpMsWorkplanInformation; //"待审核"
                    // 完成情况
                    this.formFinishData = res.data.yjQmpMsWorkplanInformation; // 完成情况
                    this.formFinishData.recordfiles = []; //文件
                    // 完成情况
                    // 计划审核
                    this.planReviewData = res.data.yjQmpMsWorkplanInformation; //"待审核"
                } else if (this.currentStatus.fStatuss == '已完成') {
                    this.formData = res.data.yjQmpMsWorkplanInformation;
                    this.formData.fAffiliationyear = data.fAffiliationyear.substr(0, 4);
                    this.fWorkfilelist = res.data.fWorkfilelist; //计划资料附件
                    // 完成情况
                    this.formFinishData = res.data.yjQmpMsWorkplanInformation; // 完成情况
                    this.formFinishData.recordfiles = []; //文件
                    // 完成情况
                    // 计划审核
                    this.planReviewData = res.data.yjQmpMsWorkplanInformation; //"待审核"
                    this.planFinishReviewData = res.data.yjQmpMsWorkplanInformation; //   完成审核
                } else if (this.currentStatus.fStatuss == '审核未通过') {
                    this.formData = res.data.yjQmpMsWorkplanInformation;
                    this.formData.fAffiliationyear = data.fAffiliationyear.substr(0, 4);
                    this.fWorkfilelist = res.data.fWorkfilelist; //计划资料附件
                    // 计划审核
                    this.planReviewData = res.data.yjQmpMsWorkplanInformation; //"待审核"
                } else if (this.currentStatus.fStatuss == '已打回') {
                    this.formData = res.data.yjQmpMsWorkplanInformation;
                    this.formData.fAffiliationyear = data.fAffiliationyear.substr(0, 4);
                    this.fWorkfilelist = res.data.fWorkfilelist; //计划资料附件
                    //  计划审核
                    this.planReviewData = res.data.yjQmpMsWorkplanInformation; //"待审核"
                    this.formFinishData = res.data.yjQmpMsWorkplanInformation; // 完成情况
                    this.formFinishData.recordfiles = []; //文件
                }
                this.FinishfileList = res.data.fFinishfileurllist;
            });
        },
        // 刪除文件
        delteFile(file, num) {
            var arr = [];
            var obj = [];
            if (num == 0) {
                arr = this.fWorkfilelist;
                obj = this.formData;
            } else if (num == 1) {
                arr = this.FinishfileList;
                obj = this.formFinishData;
            }
            for (let index = 0; index < arr.length; index++) {
                if (file.uid == arr[index].uid) {
                    if (arr[index].atta == undefined) {
                        obj.recordfiles.push({
                            fId: arr[index].fId,
                        });
                    } else {
                        obj.recordfiles.push({
                            fId: arr[index].atta.fId,
                        });
                    }
                    arr.splice(index, 1);
                }
            }
        },
        yj_saveForm() {
            if (this.statusNum == 1) { //新增
                this.formData.fType = this.stationtype;
                this.formData.userId = this.userInfo.userId; //当前登录人id
                this.formData.userName = this.userInfo.realName; //当前登录人名称
                this.formData.fProjectname = this.projectNames; //当前登录人项目名称(如果是项目部的保存接口,传这个人的所在上级的项目id)
                this.formData.fProjectid = this.projectId; //当前登录人项目ID
                this.formData.fCompanyname = this.userInfo.companyName; //当前登录人标段名称
                this.formData.fCompanyid = this.userInfo.companyId; //当前登录人标段ID
                this.formData.fSubcheckunitid = this.projectId; //提交审核人的单位id
                if (this.$refs.publicForm.submitForm()) {
                    this.saveForm(this.formData, 0);
                } else {
                    console.log("error");
                }
            } else if (this.statusNum == 2) { //完成情况
                this.formFinishData.userId = this.userInfo.userId; //当前登录人id
                this.formFinishData.userName = this.userInfo.realName; //当前登录人名称
                this.formFinishData.fId = this.dataInfo
                this.formFinishData.fFinshsubcheckunitid = this.projectId
                if (this.$refs.formFinishForm.submitForm()) {
                    this.saveForm(this.formFinishData, 1);
                } else {
                    console.log("error");
                }
            } else if (this.statusNum == 3) { //编辑
                if (this.$refs.publicForm.submitForm()) {
                    this.formData.fType = this.stationtype;
                    this.saveForm(this.formData, 0);
                } else {
                    console.log("error");
                }
            } else if (this.statusNum == 6) { //审核
                //审核
                if (this.currentStatus.fStatuss == "待审核") {
                    // 计划审核
                    this.planReviewData.fCheckid = this.userInfo.userId; //审核人id
                    this.planReviewData.fCheckname = this.userInfo.realName; //审核人姓名
                    this.planReviewData.fCheckunitname = this.projectNames; //审核人所在的单位id
                    this.planReviewData.fCheckunitid = this.projectId; //审核人所在的单位名称
                    this.planReviewData.userId = this.userInfo.userId; //当前登录人id
                    this.planReviewData.userName = this.userInfo.realName; //当前登录人名称
                    this.planReviewData.fId = this.dataInfo
                    if (this.$refs.planReview.submitForm()) {
                        this.yj_examine(this.planReviewData, 0);

                    } else {
                        console.log("error");
                    }
                } else if (this.currentStatus.fStatuss == "审核中") {
                    // 完成审核
                    this.planFinishReviewData.fFinshcheckid = this.userInfo.userId; //完成情况审核人id
                    this.planFinishReviewData.fFinshcheckname = this.userInfo.realName; //完成情况审核人姓名
                    this.planFinishReviewData.fFinshcheckunitid = this.projectId; //完成情况审核人单位id
                    this.planFinishReviewData.fFinshcheckunitname = this.projectName; //完成情况审核人单位名称
                    this.planFinishReviewData.userId = this.userInfo.userId; //当前登录人id
                    this.planFinishReviewData.userName = this.userInfo.realName; //当前登录人名称
                    this.planFinishReviewData.fId = this.dataInfo
                    if (this.$refs.planFinishReview.submitForm()) {
                        this.yj_examine(this.planFinishReviewData, 1);

                    } else {
                        console.log("error");
                    }
                }
            }
        },
        // 保存
        saveForm(data, status) {
            // 设置按钮不可点击（disable: false）

            if (status == 0) {
                this.isLock = true
                saveWorkplanInformation(data)
                    .then((res) => {
                        if (res.errcode == 0) {
                            this.isLock = false
                            this.visible = false;
                            this.$emit("refreshList");
                            this.$message.success("新增成功");
                        } else {
                            this.isLock = false
                            this.$message.error(res.msg);
                            console.log("接口报错");
                        }
                    })
                    .catch((error) => {
                        console.log("拌合站设置-新增）", error);
                    });
            } else if (status == 1) { //完成情况
                this.isLock = true
                saveWorkplanFinishInformation(data)
                    .then((res) => {
                        if (res.errcode == 0) {
                            this.isLock = false
                            this.visible = false;
                            this.$emit("refreshList");
                            this.$message.success("新增成功");
                        } else {
                            this.isLock = false
                            this.$message.error(res.msg);
                            console.log("接口报错");
                        }
                    })
                    .catch((error) => {
                        console.log("拌合站设置-新增）", error);
                    });
            }
        },
        // 审核
        yj_examine(data, status) {

            if (status == 0) {
                this.isLock = true
                // 计划审核
                CheckWorkplanInformation(data).then((res) => {
                    // if(res)
                    console.log(res);
                    if (res.errcode == 0) {
                        this.isLock = false
                        this.visible = false;
                        this.$emit("refreshList");
                    } else {
                        this.isLock = false
                    }

                });
            } else if (status == 1) {
                this.isLock = true
                CheckWorkplanFinishInformation(data).then((res) => {
                    if (res.errcode == 0) {
                        this.isLock = false

                        this.visible = false;
                        this.$emit("refreshList");
                    } else {
                        this.isLock = false
                    }
                });
            }
        },
        inputFocus(index, prop) {
            this.propTitle = prop
            if (prop == 'fCcpeople' || prop == 'fFinishccpeople') { //传阅人
                this.dialogTree = true;
                this.getBaseCompanyList();
            }
        },
        getBaseCompanyList() {
            this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
            if(this.userInfo.companyNature == '施工单位'){
                this.companyInfo = [{
                    fShortname: this.userInfo.companyName,
                    fCompanyid: this.userInfo.companyId,
                }, {
                    fShortname: this.userInfo.projectFullName,
                    fCompanyid: this.userInfo.projectId,
                }, ]
            }else{
                this.companyInfo = [{
                    fShortname: "山西路桥",
                    fCompanyid: "99ca0578-fceb-4f58-b1b2-dbec0db96e6e",
                },{
                    fShortname: this.userInfo.companyName,
                    fCompanyid: this.userInfo.companyId,
                } ]
            }
            // 全部人员
            this.companyInfo.map((item) => {
                this.getUser(item.fCompanyid);
            });
            // 全部人员

        },
        selectCompanys(e, index) {
            for (let i in this.companyInfo) {
                if (parseFloat(i) === index) {
                    this.companyInfo[i].show = true;
                } else {
                    this.companyInfo[i].show = false;
                }
            }
            this.departmentList = [];
            // this.personList = []; //单选
            this.personList = []; //多选
            this.num = null;
            this.getBaseDepartmentUserFun(e.fCompanyid);
        },
        // 部门管理-查询部门列表以及下属人员
        getBaseDepartmentUserFun(id) {
            getBaseDepartmentUser({
                    fCompanyid: id
                })
                .then((res) => {
                    if (res.errcode == 0) {
                        this.departmentList = res.data.childList;
                    } else {
                        this.$message.error("部门管理-查询部门列表以及下属人员", res.msg);
                    }
                })
                .catch((error) => {
                    console.log("部门管理-查询部门列表以及下属人员,接口报错", error);
                });
        },
        // 选择部门
        seletDepartment(e) {
            this.num = e.fDepartmentId;
            let obj = {};
            // 多选
            this.personList = [];
            this.personList = e.personList.reduce(function (item, next) {
                //item为没有重复id的数组，next为当前对象
                obj[next.fUserid] ?
                    "" :
                    (obj[next.fUserid] = true && item.push(next));
                return item;
            }, []);


        },
        selectRealname(e, data) {
            this.allUserInfo = this.allUserInfo.concat(data);
            let obj = {};
            let reduce = [];
            reduce = this.allUserInfo.reduce((item, next) => {
                //item为没有重复id的数组，next为当前对象
                obj[next.fUserid] ? "" : (obj[next.fUserid] = true && item.push(next));
                return item;
            }, []);

            this.newData = [];
            reduce.map((item) => {
                this.checkboxGroup.map((i) => {
                    if (item.fUserid == i) {
                        this.newData.push(item);
                    }
                });
            });
        },
        getUser(id) {
            getBaseDepartmentUser({
                    fCompanyid: id
                })
                .then((res) => {
                    if (res.errcode == 0) {
                        res.data.childList.map((v) => {
                            v.personList.map((item) => {
                                this.getUserInitialList.push(item);
                            });
                        });
                        // 处理选人回填--多选

                        this.newData = [];
                        this.checkboxGroup = [];
                        this.allUserInfo = [];

                        this.getUserInitialList.map((item) => {
                            this.formData.fCcpeopleid.split(",").map((v) => {
                                if (v == item.fUserid) {
                                    this.newData.push(item);
                                    this.checkboxGroup.push(item.fUserid);
                                    this.allUserInfo.push(item);
                                }
                            });
                        });
                        // 单选回填
                    } else {
                        this.$message.error(res.msg);
                        console.log("部门管理-查询部门列表以及下属人员,接口报错");
                    }
                })
                .catch((error) => {
                    console.log("部门管理-查询部门列表以及下属人员", error);
                });
        },
        // 删除用户--多选
        deteleUser(title, id) {
            this.newData = this.newData.filter((item) => {
                return item.fUserid != id;
            });
            this.checkboxGroup = this.checkboxGroup.filter((item) => {
                return item != id;
            });
        },
        // 保存 
        submitMember(title) {
            // 抄送人1
            this.userList = [];
            this.userListId = [];
            this.newData.map((item) => {
                this.userList.push(item.fRealname);
                this.userListId.push(item.fUserid);
            });
            if (title == 'fCcpeople') {
                this.formData.fCcpeople = this.userList.join(","); //抄送人姓名集合
                this.formData.fCcpeopleid = this.userListId.join(","); //抄送人id集合
            } else if (title == 'fFinishccpeople') {
                this.formFinishData.fFinishccpeople = this.userList.join(","); //抄送人姓名集合
                this.formFinishData.fFinishccpeopleid = this.userListId.join(","); //抄送人id集合
            }
            this.dialogTree = false;

        },
        getPerson(data) {
            var obj = {
                fCompanyid: data,
            };
            getBaseDepartmentUser(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        console.log("水稳", res.data.childList[0].personList);
                        var arr = res.data.childList[0].personList;
                        //工作计划信息新增options
                        // formObj
                        var personList = [];
                        arr.map((item) => {
                            personList.push({
                                label: item.fRealname,
                                value: item.fUserid,
                            });
                        });
                        this.formObj[10].options = personList;
                        this.formObj[11].options = personList;
                        this.formFinishObj[6].options = personList;
                        this.formFinishObj[7].options = personList;
                    } else {
                        this.$message.error(res.msg);
                        return false;
                    }
                })
                .catch((error) => {
                    console.log(error);
                });
        },

    },
};